<?php
if(empty($buid)&&empty($_GET['type']))
msg($config['weburl']."/login.php?forward=".urlencode("$config[weburl]/?m=product&s=shop_order"));
else
{
	if(!empty($buid))
	{
		//区域
		$sql = "select * from ".DISTRICT." where pid = 0 ";
		$db->query($sql);
		$prov = $db->getRows();
		$tpl->assign("prov",$prov);
		$id = intval($_GET['id']);
		$sql = "select s.*,p.pname from ".SETMEAL." s left join ".PRO." p on p.id = s.pid where s.id = '$id'   ";
		$db->query($sql);
		$de = $db->fetchRow();
		$tpl->assign('de',$de);
		$user_id = bgetcookie("USERID");

		foreach($_POST as $key => $val){
			if(!is_array($val)){
				$param[$key] = htmlspecialchars(stripslashes($val));
			} else {
				$param[$key] = $val;
			}
		}
		if($param['act'] == 'stock'){
			$time = time();
			$sql = "insert into ".PROSTOCK." (user_id,user_name,product_id,product_name,price,user_mobile,provinceid,cityid,areaid,user_addr,add_at,num) values
					('{$user_id[0]}','{$param['user_name']}','{$param['product_id']}','{$param['product_name']}','{$param['price']}','{$param['user_mobile']}',
					'{$param['provinceid']}','{$param['cityid']}','{$param['areaid']}','{$param['user_addr']}','$time','{$param['num']}')";
			if($db->query($sql)){
				msg($config['weburl']."/main.php?m=product&s=admin_stock","登记成功");
			} else {
				msg($config['weburl']."/?m=product&s=detail&id=".$param['product_id'],"登记失败");
			}
			}


	}
}
//=================================================
$tpl->assign("config",$config);
$tpl->assign("current","product");
include_once("footer.php");

$out=tplfetch("shop_stock.htm",$flag,true);

?>